package com.neu.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.neu.dao.ShoppingOrderMapper;
import com.neu.vo.ShoppingOrder;
import com.neu.vo.ShoppingOrderGoods;
import com.neu.vo.Shoppingvo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created by yinjian by 2019/11/25
 * 订单管理 尹健
 */
@Service
@Transactional
public class ShoppingOrderService {

    @Autowired
    private ShoppingOrderMapper shoppingOrderMapper;

    //获取订单列表信息
    public Object list(ShoppingOrder shoppingOrder) {
        if ("".equals(shoppingOrder.getOrderSn())){
            shoppingOrder.setOrderSn(null);
        }
       if (shoppingOrder.getOrderStatuslist().size() == 0){
           shoppingOrder.setOrderStatuslist(null);
       }
        PageHelper.startPage(shoppingOrder.getPagenum(),shoppingOrder.getPagesize());
        List<ShoppingOrder> list = shoppingOrderMapper.selectByExample(shoppingOrder);
        return new PageInfo<ShoppingOrder>(list);
    }

    //查看订单详情
    public Object detail(ShoppingOrderGoods shoppingOrderGoods) {
        Shoppingvo shoppingvo = new Shoppingvo();
//        List<ShoppingOrderGoods> list1 = shoppingOrderMapper.selectByPrimaryKey(shoppingOrderGoods);
//        shoppingvo.setShoppingOrderGoodsList(list1);
//        List<ShoppingOrder> list2 = shoppingOrderMapper.selectByExample1(shoppingOrderGoods);
//        shoppingvo.setShoppingOrderList(list2);
        shoppingvo.setShoppingOrderGoods(shoppingOrderMapper.selectByPrimaryKey(shoppingOrderGoods));
        shoppingvo.setShoppingOrder(shoppingOrderMapper.selectByExample1(shoppingOrderGoods));
        return shoppingvo;
    }

    //订单发货
    public int updateWithOptimisticLocker(ShoppingOrder shoppingOrder) {
        return shoppingOrderMapper.updateWithOptimisticLocker(shoppingOrder);
    }

    //订单退款
    public int queryByOid(ShoppingOrder shoppingOrder) {
        return shoppingOrderMapper.updateByExample(shoppingOrder);
    }
}
